function [img,rad] = get_image(identifier,imgSize,varargin)
%draws an image coresponding to the identifier
%
%
%author: Sebastian Schmelcher version: alpha

switch identifier
    case 'ball'
        %ball,imgSize,center,fading
        %'ball',[1024,1024],'mid','lin30_35'
        if(nargin<3)
            img=get_image(identifier,imgSize,'mid','lin30_35');
        else
            n=imgSize(1);
            m=imgSize(2);
            if(ischar(varargin{1}) && strcmp(varargin{1},'mid'))
                origin=get_origin([n,m]);
            else
                origin=varargin{1};
            end
            [X,Y]=meshgrid(1-origin(1):n-origin(1),1-origin(2):m-origin(2));
            [~,rad]=cart2pol(X,Y);
            switch varargin{2}(1:3)
                case 'lin'
                    img=(rad<=(str2double(varargin{2}(4:5)).*max(imgSize)/100));
                    img=img+(rad>(str2double(varargin{2}(4:5)).*max(imgSize)/100)).*(rad<=(str2double(varargin{2}(7:8)).*max(imgSize)/100)).*(rad-(str2double(varargin{2}(7:8)).*max(imgSize)/100))./((str2double(varargin{2}(4:5)).*max(imgSize)/100)-(str2double(varargin{2}(7:8)).*max(imgSize)/100));
                case 'srp'
                    img=(rad<=(str2double(varargin{2}(4:end)).*max(imgSize)/100));
                case 'cos'
                    img=(rad<=(str2double(varargin{2}(4:5)).*max(imgSize)/100));
                    arg=1-(rad-(str2double(varargin{2}(7:8)).*max(imgSize)/100))./((str2double(varargin{2}(4:5)).*max(imgSize)/100)-(str2double(varargin{2}(7:8)).*max(imgSize)/100));
                    img=img+(rad>(str2double(varargin{2}(4:5)).*max(imgSize)/100)).*(rad<=(str2double(varargin{2}(7:8)).*max(imgSize)/100)).*(.5*cos(arg.*pi)+.5);
                case 'tst'
                    num1=str2double(varargin{2}(4:5)).*max(imgSize)/100;
                    num2=str2double(varargin{2}(7:8)).*max(imgSize)/100;
                    if(num1==0)
                        img=(rad<num2).*exp(num2^2./(rad.^2-num2^2))/exp(-1);
                        img(isnan(img))=0;
                    else
                        img=(rad<num2).*(rad>num1).*(exp((num2-num1)^2./((rad-num1).^2-(num2-num1)^2)))/exp(-1);
                        img(rad<=num1)=1;
                        img(isnan(img))=0;
                    end
                otherwise
            end
        end
    case 'edge'
        %edge,imgSize,center,fading
        %'edge',[1024,1024],'mid','srp_045
        n=imgSize(1);
        m=imgSize(2);
        if(ischar(varargin{1}) && strcmp(varargin{1},'mid'))
            origin=get_origin([n,m]);
        else
            origin=varargin{1};
        end
        [X,Y]=meshgrid(1-origin(1):n-origin(1),1-origin(2):m-origin(2));
        [theta,~]=cart2pol(X,Y);
        switch varargin{2}(1:3)
            case 'srp'
                angl=mod(str2double(varargin{2}(4:end))/180*pi,360);
                
                if(angl<pi)
                    img=(theta<(-angl))+(theta>(pi-angl));
                else
                    angl=angl-pi;
                    img=~((theta<-angl)+(theta>(pi-angl)));
                end
            otherwise
        end
    case 'phantomI'
        img=.5*ones(imgSize);
        img=img+.5*get_image('ball',imgSize,'mid','tst20_25')-(get_image('ball',imgSize,'mid','tst20_25').*get_image('edge',imgSize,'mid','srp00'));
%     case 'phantomIl'
%         img=.5*ones(imgSize);
%         img=img+.5*get_image('ball',imgSize,'mid','lin20_25')-(get_image('ball',imgSize,'mid','lin20_25').*get_image('edge',imgSize,'mid','srp00'));
%     case 'phantomIa'
%         img=.5*ones(imgSize);
%         img=img+.5*get_image('ball',imgSize,'mid','lin20_25')-(get_image('ball',imgSize,'mid','lin20_25').*get_image('edge',imgSize,'mid','srp45'));
%     case 'phantomII'
%         img=.5*ones(imgSize);
%         img=img+.5*get_image('ball',imgSize,'mid','tst20_25')-(get_image('ball',imgSize,'mid','tst20_25').*get_image('edge',imgSize,'mid','srp00'));
%     case 'phantomIIs'
%         img=.5*ones(imgSize);
%         img=img+.5*get_image('ball',imgSize,'mid','srp25')-(get_image('ball',imgSize,'mid','srp25').*get_image('edge',imgSize,'mid','srp00'));
%     case 'phantomIIa'
%         img=.5*ones(imgSize);
%         img=img+.5*get_image('ball',imgSize,'mid','srp25')-(get_image('ball',imgSize,'mid','srp25').*get_image('edge',imgSize,'mid','srp45'));
    case 'phantomII'
        img=.5*ones(imgSize);
        img=img+.5*get_image('ball',imgSize,'mid','tst00_25')-(get_image('ball',imgSize,'mid','tst00_25').*get_image('edge',imgSize,'mid','srp00'));
    case 'phantomIII'
        img=.5*ones(imgSize);
        img=img+.5*get_image('ball',imgSize,'mid','tst20_25')-(get_image('ball',imgSize,'mid','tst20_25').*...
            (get_image('edge',imgSize,'mid','srp00').*get_image('edge',imgSize,'mid','srp270')+get_image('edge',imgSize,'mid','srp90').*get_image('edge',imgSize,'mid','srp180')));
    case 'phantomIIIs'
        img=.5*ones(imgSize);
        img=img+.5*get_image('ball',imgSize,'mid','srp25')-(get_image('ball',imgSize,'mid','srp25').*...
            (get_image('edge',imgSize,'mid','srp00').*get_image('edge',imgSize,'mid','srp270')+get_image('edge',imgSize,'mid','srp90').*get_image('edge',imgSize,'mid','srp180')));
    case 'phantomIV'
        img=.5*ones(imgSize);
        img=img+.5*get_image('ball',imgSize,'mid','tst00_25')-(get_image('ball',imgSize,'mid','tst00_25').*...
            (get_image('edge',imgSize,'mid','srp00').*get_image('edge',imgSize,'mid','srp270')+get_image('edge',imgSize,'mid','srp90').*get_image('edge',imgSize,'mid','srp180')));
    case 'phantomV'
        img=.5*ones(imgSize);
        for i=60:110:imgSize(1)-60
            for j=60:110:imgSize(2)-60
                loc=[i,j];
                img=img+.5*get_image('ball',imgSize,loc,'tst02_05')-(get_image('ball',imgSize,loc,'tst02_05').*...
                (get_image('edge',imgSize,loc,'srp00').*get_image('edge',imgSize,loc,'srp270')+get_image('edge',imgSize,loc,'srp90').*get_image('edge',imgSize,loc,'srp180')));
            end
        end 
%     case 'phantomIVl'
%         img=.5*ones(imgSize);
%         for i=60:110:imgSize(1)-60
%             for j=60:110:imgSize(2)-60
%                 loc=[i,j];
%                 img=img+.5*get_image('ball',imgSize,loc,'lin02_05')-(get_image('ball',imgSize,loc,'lin02_05').*...
%                 (get_image('edge',imgSize,loc,'srp00').*get_image('edge',imgSize,loc,'srp270')+get_image('edge',imgSize,loc,'srp90').*get_image('edge',imgSize,loc,'srp180')));
%             end
%         end
%     case 'phantomIVa'
%         img=.5*ones(imgSize);
%         for i=60:110:imgSize(1)-60
%             for j=60:110:imgSize(2)-60
%                 loc=[i,j];
%                 img=img+.5*get_image('ball',imgSize,loc,'srp05')-(get_image('ball',imgSize,loc,'srp05').*...
%                 (get_image('edge',imgSize,loc,'srp45').*get_image('edge',imgSize,loc,'srp315')+get_image('edge',imgSize,loc,'srp135').*get_image('edge',imgSize,loc,'srp225')));
%             end
%         end
    case 'phantomVI'
        img=.5*ones(imgSize);
        for i=60:110:imgSize(1)-60
            for j=60:110:imgSize(2)-60
                loc=[i,j];
                img=img+.5*get_image('ball',imgSize,loc,'tst00_05')-(get_image('ball',imgSize,loc,'tst00_05').*...
                (get_image('edge',imgSize,loc,'srp00').*get_image('edge',imgSize,loc,'srp270')+get_image('edge',imgSize,loc,'srp90').*get_image('edge',imgSize,loc,'srp180')));
            end
        end 

        
    otherwise
end
